var choooseDatasByRedio = '';
/**
 * 质检上架单
 */
app.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http){
    console.log('------$scope.menuId1-----', $scope.menuId);
    console.log('------$scope.buttonArr1-----', $scope.buttonArr);

    $scope.bindBtn = function(event) {
        var datas = $scope.getSelectedRows();
        switch(event){
            case 'event-to-export': {//导出
                $scope.doExport('/api/inter/tccPuton/export');
                break;
            }
            case 'event-to-doQualityTesting': {//质检上架
                if(datas.length == 0) {
                    layer.alert('尚未选中数据');
                } else {
                    choooseDatasByRedio = JSON.stringify(datas);
                    layer.confirm('确定要质检上架所选的单据吗？', { icon: 3 }, function() {
                        $scope.showModalRadio("TCC_Location", 3, 'aaaa', null, {});

                        /*
                        window.matchValuesAfterModalSelectRadio = function(colCode, data, extraData) {
                            console.log('data =',data);
                            layer.msg('处理中', { icon: 16, shade: 0.01 });
                            $http.post('/api/inter/tccPuton/doQualityTesting', {}, {params: {choooseDatas: choooseDatas,chw:data.chw}})
                                .success(function (res) {
                                    if (res.code == 0) {
                                        layer.msg(res.msg);
                                        setTimeout(function(){
                                            layer.closeAll();
                                            location.reload();
                                        }, 3000);
                                    } else {
                                        layer.msg(res.msg);
                                        layer.closeAll();
                                    }
                                })
                                .error(function(result){
                                    layer.close();
                                    layer.msg("操作失败，请稍后再试！", {icon: 2});
                                });

                        };
                        layui.YsModal.init({modalKey: 'TCC_Location', colCode: 'aaaa', parentObj: window});

                         */

                    }, function() {});
                }
                break;
            }

            case 'event-to-putonExamine'://上架审核
            {
                if(datas.length == 0) {
                    return layer.alert('尚未选中数据');
                }
                var choooseDatas = JSON.stringify(datas);
                layer.confirm('确定要上架审核所选的单据吗？', { icon: 3 }, function() {
                    layer.msg('处理中', { icon: 16, shade: 0.01 });
                    $http.post('/api/inter/tccPuton/putonExamine', {}, {params: {choooseDatas: choooseDatas}})
                        .success(function (res) {
                            if (res.code == 0) {
                                layer.msg(res.msg);
                                setTimeout(function(){
                                    layer.closeAll();
                                    location.reload();
                                }, 3000);
                            } else {
                                layer.msg(res.msg);
                                layer.closeAll();
                            }
                        })
                        .error(function(result){
                            layer.close();
                            layer.msg("操作失败，请稍后再试！", {icon: 2});
                        });

                }, function() {});
                break;
            }

        };
    }
}

//表格双击
app.controller('dbClickCtrl', ['$scope', '$http', DbClickController]);
function DbClickController($scope, $http){
    $scope.doubleClick = function(data) {
        window.top.add_tab('质检上架单 - 详情','/web/storage/tccPuton/toDetail?id=' + data.id);
    }
}


/*
 * 自定义通用控制器，若无定义，页面会报错
 */
app.controller('mainSelfCtrl', ['$scope', '$http', function GridSelfController($scope, $http){

    $scope.doSelectRadioBySelf = function(data) {
        console.log('单选框特殊回调', data);
        console.log('data =',data);
        layer.msg('处理中', { icon: 16, shade: 0.01 });
        $http.post('/api/inter/tccPuton/doQualityTesting', {}, {params: {choooseDatas: choooseDatasByRedio,chw:data.chw}})
            .success(function (res) {
                if (res.code == 0) {
                    layer.msg(res.msg);
                    setTimeout(function(){
                        layer.closeAll();
                        location.reload();
                    }, 3000);
                } else {
                    layer.msg(res.msg);
                    layer.closeAll();
                }
            })
            .error(function(result){
                layer.close();
                layer.msg("操作失败，请稍后再试！", {icon: 2});
            });
    }
}]);
